package main
{
    import flash.events.Event;    
    import mx.collections.ArrayCollection;
    import mx.controls.Alert;
    import mx.controls.CheckBox;
    import mx.events.FlexEvent;
    
    
    
    public class AllCheckBox extends CheckBox
    {
		public var isSelected: Boolean;
        
        public function AllCheckBox()
        {
        	
            super();
            this.addEventListener(Event.CHANGE,changeHandle);
            this.addEventListener(FlexEvent.DATA_CHANGE,ondc);
            this.addEventListener(FlexEvent.CREATION_COMPLETE,oncc);

   
        }
        
        private function oncc(e:FlexEvent):void
        {
        	this.selected = parentApplication.mainIsSelected;
        }
             
        private function ondc(e:FlexEvent):void       
        {   
       		this.selected = this.isSelected;
        }
        
        private function changeHandle(e:Event):void
        {
			
			var ac:ArrayCollection = parentApplication.PicXML;		
			
			if(this.selected)
			{
				parentApplication.checkBoxArr = [];
				for(var i:int=0;i<ac.length;i++)
				{
					ac[i].isSelected = true;
					parentApplication.checkBoxArr.push(ac[i].id);
				}
				parentApplication.mainIsSelected = true;

				
			}
			else
			{
				for(var j:int=0;j<ac.length;j++)
				{
					parentApplication.PicXML[j].isSelected = false;
				}
				parentApplication.mainIsSelected = false;
				parentApplication.checkBoxArr =[];
				
			}
			ac.refresh();           
        }

    }
}